package com.dcy.daily.skill.rabbitMQ.springAMQP.tmp.sendAndRecv;

import com.dcy.daily.skill.rabbitMQ.springAMQP.util.AmqpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

import java.nio.charset.StandardCharsets;

/**
 * 发送消息
 *
 * @author duanchunyu
 * @version 1.0.0
 * @createTime 2021年07月22日 11:12
 */
public class Send {
    public static final Logger logger = LoggerFactory.getLogger(Send.class);

    public static void main(String[] args) {
        RabbitTemplate rabbitTemplate = AmqpUtil.getRabbitTemplate();

        Message message = MessageBuilder.withBody("foo".getBytes(StandardCharsets.UTF_8)).build();
        rabbitTemplate.send("myqueue", message);
        rabbitTemplate.setConfirmCallback((correlationData, ack,cause) -> {
           logger.info(correlationData +"Ack: " + ack + ":" + ack);
        });
        System.out.println("send over");
    }
}
